<?php
namespace haibao\cms\business\attendance;
use \haibao\frame\data\query\Condition;
use haibao\app\business\BusinessException;
Class AttendanceDefineTmp extends \haibao\cms\business\Base{
	
	public static function addAttendanceRecord($models){
		$data = new \haibao\cms\data\attendance\AttendanceDefineTmp();
		$data->addAll($models);
	}
	
	public static function clearAttendanceRecordTmp(){
		
		$data = new \haibao\cms\data\attendance\AttendanceDefineTmp();
		$data->remove(new \haibao\cms\model\filter\attendance\AttendanceDefineTmp());
		
	}
	
	public static function getAllAttendance($minDate=null,$maxDate=null,$jobNum=null){

		$finalResult = array();
		$data = new \haibao\cms\data\attendance\AttendanceDefineTmp();
		$filter = new \haibao\cms\model\filter\attendance\AttendanceDefineTmp();
		if($minDate && $maxDate){
			$filter->where(\haibao\cms\model\filter\attendance\AttendanceDefineTmp::CONDITION_FIELD_NAME_CLICK_DATE,\haibao\frame\data\query\Condition::CONDITION_GREATEREQUAL,$minDate);
			$filter->where(\haibao\cms\model\filter\attendance\AttendanceDefineTmp::CONDITION_FIELD_NAME_CLICK_DATE,\haibao\frame\data\query\Condition::CONDITION_LESSEQUAL,$maxDate);
		}
		if($jobNum){
			$filter->where(\haibao\cms\model\filter\attendance\AttendanceDefineTmp::CONDITION_FIELD_NAME_JOB_NUM,\haibao\frame\data\query\Condition::CONDITION_EQUAL,$jobNum);
		}
		$result = $data->getAll($filter);
			
		foreach ($result as $list){
			$date = $list->ClickDate->format('Y-m-d');
			$unixTime = strtotime($date.' '.$list->ClickTime);
			$key = $list->JobNum.'_'.$list->ClickDate->format('Y-m-d');
			$finalResult[$key][] = $unixTime;
		}
		return $finalResult;
	}
	
	public static function getAllAttendanceByCreateTime($currentTime){
		$finalResult = array();
		$data = new \haibao\cms\data\attendance\AttendanceDefineTmp();
		$filter = new \haibao\cms\model\filter\attendance\AttendanceDefineTmp();
		$filter->where(\haibao\cms\model\filter\attendance\AttendanceDefineTmp::CONDITION_FIELD_NAME_CREATE_TIME,\haibao\frame\data\query\Condition::CONDITION_GREATEREQUAL,$currentTime);
		$result = $data->getAll($filter);
		foreach ($result as $list){
			$date = $list->ClickDate->format('Y-m-d');
			$unixTime = strtotime($date.' '.$list->ClickTime);
			$key = $list->JobNum.'_'.$list->ClickDate->format('Y-m-d');
			$finalResult[$key][] = $unixTime;
		}
		return $finalResult;
	}
	
	public static function getUserAttendanceRecord($jobNum,$clickDate,$clickTime){

		$data = new \haibao\cms\data\attendance\AttendanceDefineTmp();
		return $data->getUserAttendanceRecord($jobNum,$clickDate,$clickTime);
	}
}
